home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / radio.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.1 KB  |  119 lines

  1. // $Id: radio.cc 1.3 1997/09/17 08:16:41 dlorre Exp dlorre $
  2. #include <libraries/gadtools.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5.  
  6. #include "gadgets/radio.h"
  7. #include "gadgetlist.h"
  8.  
  9. #include <proto/gadtools.h>
  10. #include <proto/utility.h>
  11.  
  12. // ========================================================================
  13. // ==========================  RADIO CLASS ================================
  14. // ========================================================================
  15.  
  16.  
  17. radio::radio(gadgetlist *gl,
  18.              void (window::*func)(gadget *, unsigned long, unsigned short),
  19.              TagItem *tags) :
  20.              gadget(gl, func), labsize(1), mxlabs(NULL)
  21. {
  22.     init(tags) ;
  23. }
  24. radio::radio(gadgetlist *gl,
  25.              void (window::*func)(gadget *, unsigned long, unsigned short),
  26.              ULONG tag1, ...) :
  27.              gadget(gl, func), labsize(1), mxlabs(NULL)
  28. {
  29.     init((TagItem *)&tag1) ;
  30. }
  31.  
  32. radio::~radio()
  33. {
  34.     if (mxlabs) {
  35.     int i ;
  36.         for (i=0; i<labsize; i++)
  37.             if (mxlabs[i]) delete mxlabs[i] ;
  38.         delete mxlabs ;
  39.     }
  40. }
  41.  
  42. void radio::init(TagItem *tags)
  43. {
  44. const char **p, **text = NULL ;
  45. const char *cp ;
  46. int i = 0 ;
  47. TagItem *t, *tl ;
  48.  
  49.     cursel = (LONG)GetTagData(ORADIO_Active, 0, tags) ;
  50.     glist->ng->ng_Flags = GetTagData(ORADIO_Flags, PLACETEXT_LEFT, tags) ;
  51.     spacing = (LONG)GetTagData(ORADIO_Spacing, 2, tags) ;
  52.  
  53.     if (FindTagItem(ORADIO_TextArray, tags)) {
  54.         text = p = (const char **)GetTagData(ORADIO_TextArray, NULL, tags) ;
  55.         cp = *p++ ;
  56.         while (cp) {
  57.             labsize++ ;
  58.             cp = *p++ ;
  59.         }
  60.      }
  61.     else {
  62.         tl = tags ;
  63.         while (t = NextTagItem(&tl)) {
  64.             if (t->ti_Tag == ORADIO_Text) {
  65.                 labsize++ ;
  66.             }
  67.         }
  68.         mxlabs = new STRPTR[labsize] ;
  69.         tl = tags ;
  70.         while (t = NextTagItem(&tl)) {
  71.             if (t->ti_Tag == ORADIO_Text) {
  72.                 cp = (const char *)GetTagData(ORADIO_Text, NULL, t) ;
  73.                 mxlabs[i] = new char[strlen(cp)+1] ;
  74.                 strcpy(mxlabs[i++], cp) ;
  75.             }
  76.         }
  77.         mxlabs[i] = NULL ;
  78.     }
  79.     if ((glist->top+(labsize-1)*(glist->height+spacing) - spacing) > glist->maxh)
  80.         glist->maxh = (WORD)glist->top + (labsize-1)*(glist->height+spacing) - spacing ;
  81.  
  82.     gad = glist->gad = CreateGadget(MX_KIND, glist->gad, glist->ng,
  83.             GTMX_Labels,    mxlabs ? mxlabs : text,
  84.             GTMX_Active,    cursel,
  85.             GTMX_Spacing,   spacing,
  86.             GTMX_Scaled,    TRUE,
  87.             GT_Underscore,  '_',
  88.             TAG_END) ;
  89. }
  90.  
  91.  
  92. void radio::action(unsigned long classe, unsigned short code)
  93. {
  94.     cursel = code ;
  95.     curstring = mxlabs[cursel] ;
  96.     gadget::action(classe, code) ;
  97. }
  98.  
  99. void radio::keystroke(BOOL shifted)
  100. {
  101.     if (shifted) {
  102.         cursel-- ;
  103.         if (cursel < 0) cursel=labsize-2 ;
  104.     }
  105.     else {
  106.         cursel++ ;
  107.         if (cursel > (labsize-2))
  108.             cursel = 0 ;
  109.     }
  110.     GT_SetGadgetAttrs(gad, w, NULL,
  111.         GTMX_Active,    cursel,
  112.         TAG_DONE) ;
  113.     curstring = mxlabs[cursel] ;
  114.     gadget::action(NULL, cursel) ;
  115. }
  116.  
  117.  
  118.  
  119.